<template>
  <a-modal
    title="新建用户"
    :width="600"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
    okText="确认"
    cancelText="取消"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row>
          <a-row :gutter="12">
            <a-col :md="12" :sm="24">
              <a-form-item
                label="用户姓名"
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
              >
                <a-input v-decorator="['wjmName']" />
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-form-item
                label="联系电话"
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
              >
                <a-input v-decorator="['wjmTel']" />
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-form-item
                label="备注信息"
                :labelCol="labelCol"
                :wrapperCol="wrapperCol"
              >
                <a-input v-decorator="['wjmInfo']" />
              </a-form-item>
            </a-col>
          </a-row>
        </a-row>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>

// eslint-disable-next-line standard/object-curly-even-spacing
import { addWjm } from '@/api/basic/wjm'

export default {
  name: 'AddWjm',
  components: {
  },
  props: {
  },
  data () {
    return {
      treeData: [],
      expandedKeys: [1],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      visible: false,
      confirmLoading: false,
      persons: [],
      wjmUnitName: '',
      units: [],

      form: this.$form.createForm(this)
    }
  },
  created () {
  },
  methods: {
    add () {
      this.visible = true
    },
    handleSubmit () {
      const { form: { validateFields } } = this
      this.confirmLoading = true
      validateFields((errors, values) => {
        if (!errors) {
                addWjm(values)
                  .then(res => {
                    if (res.message !== 'error') {
                      this.visible = false
                      this.confirmLoading = false
                      this.form.resetFields()
                      this.$emit('ok')
                    } else {
                      this.confirmLoading = false
                      this.$message.error('操作失败！')
                    }
                  })
        } else {
          this.confirmLoading = false
        }
      })
    },
    handleCancel () {
      this.form.resetFields()
      this.visible = false
    }
  }
}
</script>
